/**
 * Created by IntelliJ IDEA.
 * User: jiyufei
 * Date: 2018/11/12
 * Time: 15:20
 **/
package com.jiyufei.secure;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SecureSessionIdGenerator {
    
    private Long sessionId;
    private SimpleDateFormat sdf,sdf2;
    private int dateInt;
    
    
    public SecureSessionIdGenerator(){
        sdf = new SimpleDateFormat("yyyyMMdd");
        sdf2 = new SimpleDateFormat("MMdd");
        nowData(0);
    }
    
    public SecureSessionIdGenerator(int start){
        sdf = new SimpleDateFormat("yyyyMMdd");
        sdf2 = new SimpleDateFormat("MMdd");
        nowData(start);
    }
    
    
    public Long nowData(int start){
        try {
            String now = sdf.format(new Date());
            dateInt = Integer.parseInt(now) - 20000000;
            sessionId = (long) dateInt * 10000000 + start;
        }catch (Exception e){
            return 1800000000000L;
        }
        return sessionId;
    }
    
    
    
    
    public long getSessionId(){
        
        sessionId++;
        return sessionId;
    }
    
    
}
